/**********************************************************************
 * Project : WoWGuildRoster (http://www.codeplex.com/WowGuildRoster/)
 * Module  : DotNetWarcraft.WoWGuildRoster.Business.QuickStatListItem
 **********************************************************************
 * 
 * 
 * 
 **********************************************************************
 * License : All code is subject to licensing terms per the Microsoft
 *   Permissive License (Ms-PL) v1.1. For full license information,
 *   refer to the packaged license.txt file.
 **********************************************************************
 * Revision History:
 * -----------------
 * 2007-10-07 -- Cliff Simpkins: Initial Version with properties and constructors
 **********************************************************************
 */
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;

using DotNetWarcraft.Common;

namespace DotNetWarcraft.WoWGuildRoster.Business {
  /// <summary>
  /// This is an alternate class to GuildEntryStat. This class is meant to store
  ///   information from the database - for showing lists of characters by a
  ///   given stat.
  /// </summary>
  public class QuickStatListItem {
  #region Private Members
    protected int _char_id;
    protected int _charstat_id;

    //Basic character information
    protected String _char_name;
    protected String _char_race;
    protected String _char_gender;
    protected String _char_class;
    protected int _char_level;
    protected DateTime _game_last_login;

    protected int _primary_char_flag;
    protected int _alt_to_main_id;

    //Basic stat information
    protected int _stat_type;
    protected String _stat_group;
    protected String _stat_entry;
    protected int _stat_value_int;
    protected double _stat_value_dec;
    protected String _stat_value_str;
  #endregion
  #region Public Properties
    public int CharStat_ID {
      get { return _charstat_id; }
      set { _charstat_id = value; }
    }
    public int Char_ID {
      get { return _char_id; }
      set { _char_id = value; }
    }
    public int Roster_ID {
      get;
      set;
    }

    public String Char_Name {
      get	{ return _char_name; }
      set	{ _char_name = value; }
    }
    public String Char_Race {
      get {return _char_race;}
      set {_char_race = value;}
    }
    public String Char_Gender {
      get {return _char_gender;}
      set {_char_gender = value;}
    }
    public String Char_Class {
      get	{ return _char_class; }
      set	{ _char_class = value; }
    }
    public int Char_Level {
      get	{ return _char_level; }
      set	{ _char_level = value; }
    }
    public String Char_Server {
      get;
      set;
    }
    public String Char_Guild {
      get;
      set;
    }
    public int Game_Guild_Rank {
      get;
      set;
    }

    public String Char_Spec {
      get;
      set;
    }
    public int Char_Spec1_Level {
      get;
      set;
    }
    public int Char_Spec2_Level {
      get;
      set;
    }
    public int Char_Spec3_Level {
      get;
      set;
    }

    public String Char_Prof1 {
      get;
      set;
    }
    public int Char_Prof1_Level {
      get;
      set;
    }
    public String Char_Prof2 {
      get;
      set;
    }
    public int Char_Prof2_Level {
      get;
      set;
    }

    
    public DateTime Game_Last_Login {
      get	{ return _game_last_login; }
      set	{ _game_last_login = value; }
    }

    public int Primary_Char_Flag {
      get	{ return _primary_char_flag; }
      set	{ _primary_char_flag = value; }
    }
    public int Alt_to_Main_ID {
      get	{ return _alt_to_main_id; }
      set	{ _alt_to_main_id = value; }
    }

    public int Stat_Type {
      get {return _stat_type;}
      set {_stat_type = value;}
    }
    public WarcraftStatTypes Stat_Type_Enum {
      get {
        return WGRConstants.WowStatType_Enum(this.Stat_Type);
      }
      set {
        this.Stat_Type = WGRConstants.WowStatType_Int(value);
      }
    }

    public String Stat_Group {
      get {return _stat_group;}
      set {_stat_group = value;}
    }
    public String Stat_Entry {
      get {return _stat_entry;}
      set {_stat_entry = value;}
    }
    public int Stat_Value_int {
      get { return _stat_value_int; }
      set { _stat_value_int = value; }
    }
    public double Stat_Value_dec {
      get {
        return _stat_value_dec;
      }
      set {
        _stat_value_dec = value;
      }
    }
    public String Stat_Value_str {
      get { return _stat_value_str; }
      set { _stat_value_str = value; }
    }
  #endregion

  #region Constructors
    public QuickStatListItem() : base() {
      this.CharStat_ID = -1;
      this.Char_ID = -1;
      this.Roster_ID = -1;
      this.Stat_Type_Enum = WarcraftStatTypes.Unknown;

      this.Char_Server = "";
      this.Char_Guild = "";

      this.Char_Name = "";
      this.Char_Race = "";
      this.Char_Gender = "";
      this.Char_Class = "";
      this.Char_Level = -1;
      this.Game_Last_Login = DateTime.MinValue;

      this.Char_Spec = "";
      this.Char_Spec1_Level = -1;
      this.Char_Spec2_Level = -1;
      this.Char_Spec3_Level = -1;

      this.Char_Prof1 = "";
      this.Char_Prof1_Level = -1;
      this.Char_Prof2 = "";
      this.Char_Prof2_Level = -1;

      this.Game_Guild_Rank = -1;

      this.Primary_Char_Flag = 0;
      this.Alt_to_Main_ID = -1;

      this.Stat_Group = "";
      this.Stat_Entry = "";
      this.Stat_Value_int = -1;
      this.Stat_Value_dec = -1.0;
      this.Stat_Value_str = "";
    }

    public QuickStatListItem(DataRow rosterSrc) : base() {
      this.CharStat_ID = SqlDataUtils.RetrieveDbInt(rosterSrc["charstat_id"]);
      this.Char_ID = SqlDataUtils.RetrieveDbInt(rosterSrc["char_id"]);
      this.Roster_ID = SqlDataUtils.RetrieveDbInt(rosterSrc["roster_id"]);

      this.Char_Name = SqlDataUtils.RetrieveDbString(rosterSrc["char_name"]);
      this.Char_Race = SqlDataUtils.RetrieveDbString(rosterSrc["char_race"]);
      this.Char_Gender = SqlDataUtils.RetrieveDbString(rosterSrc["char_gender"]);
      this.Char_Guild = SqlDataUtils.RetrieveDbString(rosterSrc["char_guild"]);
      this.Char_Class = SqlDataUtils.RetrieveDbString(rosterSrc["char_class"]);
      this.Char_Level = SqlDataUtils.RetrieveDbInt(rosterSrc["char_level"]);
      this.Game_Last_Login = SqlDataUtils.RetrieveDbDate(rosterSrc["game_last_login"]);

      this.Char_Spec = SqlDataUtils.RetrieveDbString(rosterSrc["char_spec"]);
      this.Char_Spec1_Level = SqlDataUtils.RetrieveDbInt(rosterSrc["char_spec1_level"]);
      this.Char_Spec2_Level = SqlDataUtils.RetrieveDbInt(rosterSrc["char_spec2_level"]);
      this.Char_Spec3_Level = SqlDataUtils.RetrieveDbInt(rosterSrc["char_spec3_level"]);
      this.Char_Prof1 = SqlDataUtils.RetrieveDbString(rosterSrc["char_prof1"]);
      this.Char_Prof1_Level = SqlDataUtils.RetrieveDbInt(rosterSrc["char_prof1_level"]);
      this.Char_Prof2 = SqlDataUtils.RetrieveDbString(rosterSrc["char_prof2"]);
      this.Char_Prof2_Level = SqlDataUtils.RetrieveDbInt(rosterSrc["char_prof2_level"]);

      this.Game_Guild_Rank = SqlDataUtils.RetrieveDbInt(rosterSrc["game_guild_rank"]);

      this.Primary_Char_Flag = SqlDataUtils.RetrieveDbInt(rosterSrc["primary_char"]);
      this.Alt_to_Main_ID = SqlDataUtils.RetrieveDbInt(rosterSrc["alt_to_main"]);
      
      this.Stat_Type = SqlDataUtils.RetrieveDbInt(rosterSrc["stat_type"]);

      this.Stat_Group = SqlDataUtils.RetrieveDbString(rosterSrc["stat_group"]);
      this.Stat_Entry = SqlDataUtils.RetrieveDbString(rosterSrc["stat_entry"]);
      this.Stat_Value_int = SqlDataUtils.RetrieveDbInt(rosterSrc["stat_value_int"]);
      this.Stat_Value_dec = SqlDataUtils.RetrieveDbDec(rosterSrc["stat_value_dec"].ToString());
      this.Stat_Value_str = SqlDataUtils.RetrieveDbString(rosterSrc["stat_value_str"]);

    }
  #endregion

    /*
  #region Interpreted Properties
    public GuildEntry Character {
      get {
        if (this.Char_ID < 0) {
          return new GuildEntry();
        }

        try {
          return GuildRosterController.GetCharEntry(this.Char_ID);
        } catch {
          return new GuildEntry();
        }
      }
    }

    public GuildEntry MainCharacter {
      get {
        if (this.Alt_to_Main_ID < 0) {
          return new GuildEntry();
        }

        try {
          return GuildRosterController.GetCharEntry(this.Alt_to_Main_ID);
        } catch {
          return new GuildEntry();
        }
      }
    }
    public List<GuildEntry> AltCharacters {
      get {
        if (this.Char_ID < 0) { return null; }

        try {
          return GuildRosterController.GetCharEntries_Alts(this.Char_ID);
        } catch {
          return null;
        }
      }
    }

    public GuildEntryStat CharStatEntry {
      get {
        if (this.CharStat_ID < 0) {
          return new GuildEntryStat();
        }

        try {
          return GuildRosterController.GetCharEntryStat(this.CharStat_ID);
        } catch {
          return new GuildEntryStat();
        }
      }
    }

    public String Stat_Value {
      get {
        if (this.Stat_Value_str.Trim() != "" &&
          this.Stat_Value_str.ToLower().Trim() != this.Stat_Entry.ToLower().Trim()) {
          return this.Stat_Value_str.Trim();
        } else if (this.Stat_Value_int != -1) {
          return this.Stat_Value_int.ToString();
        } else if (this.Stat_Value_dec != -1.0) {
          return this.Stat_Value_dec.ToString();
        } else
          return "";
      }
    }
    public String Game_Last_Login_Day {
      get { return this.Game_Last_Login.ToShortDateString(); }
    }
    public String Game_Activity {
      get {
        TimeSpan _ts = DateTime.Today - this.Game_Last_Login;

        if (_ts.Days < 1) { return "Played Today"; } else if (_ts.Days <= 7) { return "Played this week"; } else if (_ts.Days <= 14) { return "Played in last couple weeks"; } else if (_ts.Days <= 31) { return "Played this month"; } else if (_ts.Days <= 60) { return "Not seen in a month"; } else if (_ts.Days <= 90) { return "Not seen in a couple months"; } else if (_ts.Days <= 180) { return "Not seen in a few months"; } else if (_ts.Days <= 360) { return "Not in at least 6 months"; } else { return "Inactive; Not seen in the last year!"; }
      }
    }

    public GuildRoster Guild {
      get {
        if (this.Roster_ID < 0) {
          return new GuildRoster();
        }

        try {
          return GuildRosterController.GetRoster(this.Roster_ID);
        } catch {
          return new GuildRoster();
        }
      }
      set {
        if (value.Roster_ID > 0) {
          this.Roster_ID = value.Roster_ID;
        }
      }
    }
    public String Game_Guild_RankName {
      get {
        if (this.Roster_ID >= 0 && this.Guild.Roster_ID >= 0) {
          return this.Guild.GetGuildRank(this.Game_Guild_Rank);
        } else
          return "N/A";
      }
    }

    public String PopupHtml {
      get {
        String _output = "";
        _output += "<span class=\\'" + this.Char_Class.ToLower() + "Ch\\'>" + this.Char_Name + "</span><br>";

        if (this.Char_Guild != null && this.Char_Guild.Trim() != "" &&
            this.Game_Guild_RankName != null && this.Game_Guild_RankName.Trim() != "") {
          _output += this.Game_Guild_RankName + " of " + this.Char_Guild + "<br>";
        } else if (this.Char_Guild.Trim() != "") {
          _output += "Of " + this.Char_Guild + "<br>";
        }
        _output += "Level " + this.Char_Level + " " + this.Char_Class + "<br>";
        if (this.Char_Level > 20) {
          if ((this.Char_Spec1_Level + this.Char_Spec2_Level + this.Char_Spec3_Level > 0) && this.Char_Spec1_Level >= 0 && this.Char_Spec2_Level >= 0 && this.Char_Spec3_Level >= 0) {
            _output += " (";
            if (this.Char_Spec != "") {
              _output += this.Char_Spec + " - ";
            }
            _output += this.Char_Spec1_Level.ToString() + "/" + this.Char_Spec2_Level.ToString() + "/" + this.Char_Spec3_Level.ToString() + ")<br>";
          } else {
            _output += "(Spec Info Unavailable)<br>";
          }
        }
        if (this.Primary_Char_Flag > 0) {
          List<GuildEntry> _alts = this.AltCharacters;
          if (_alts.Count > 0) {
            _output += "[" + _alts.Count.ToString() + " registered alts]<br>";
          } else {
            _output += "[Main character]";
          }
          _output += "<br>";
        } else if (this.Alt_to_Main_ID > 0) {
          _output += "[Alt to " + this.MainCharacter.Char_Name + "]";
          _output += "<br>";
        }

        if (this.Char_Prof1.Trim() != "" || this.Char_Prof2.Trim() != "") {
          _output += "<br>";
          if (this.Char_Prof1.Trim() != "") {
            if (this.Char_Prof1_Level > 350) {
              _output += "<span class=\\'purplename\\'>";
            } else if (this.Char_Prof1_Level > 300) {
              _output += "<span class=\\'bluename\\'>";
            } else if (this.Char_Prof1_Level > 225) {
              _output += "<span class=\\'greenname\\'>";
            } else if (this.Char_Prof1_Level > 150) {
              _output += "<span class=\\'whitename\\'>";
            } else {
              _output += "<span class=\\'greyname\\'>";
            }
            _output += this.Char_Prof1_Level.ToString() + " " + this.Char_Prof1 + "</span><br>";
          }
          if (this.Char_Prof2.Trim() != "") {
            if (this.Char_Prof2_Level > 350) {
              _output += "<span class=\\'purplename\\'>";
            } else if (this.Char_Prof2_Level > 300) {
              _output += "<span class=\\'bluename\\'>";
            } else if (this.Char_Prof2_Level > 225) {
              _output += "<span class=\\'greenname\\'>";
            } else if (this.Char_Prof2_Level > 150) {
              _output += "<span class=\\'whitename\\'>";
            } else {
              _output += "<span class=\\'greyname\\'>";
            }
            _output += this.Char_Prof2_Level.ToString() + " " + this.Char_Prof2 + "</span><br>";
          }
        }
        return _output;
      }
    }

  #endregion
     */
  #region Public Methods
  #endregion
  }
}
 